jQuery(function($) {
	loadData();
});

function loadData(){
	var data = $("#userQueryForm").serialize();
	$.ajax({
		type:"POST",
		url:dataUrl,
		data:data,
		cache:false,
		success:function(data){
			$("#context").html(data);
		}
	});
}

function openGoldDetail(userId){
	parent.window.Index.addTab(ctx + "/admin/finance/userfinance?userId="+userId,"分数明细");
}

function seeDetail(trId, target){
	var detail = $("#"+trId);
	if(detail.is(':hidden')){
        $(target).html("关闭关联玩家");
        detail.show();
	}else{
        detail.hide();
        $(target).html("查看关联玩家");
	}
}

function addUser() {
	window.location.href = 'addUser';
}
function delUser(id) {
	if(confirm("确认删除此用户吗？")){
        $.ajax({
            type:"POST",
            url:"delUser",
            data:"id="+id,
            cache:false,
            dataType:"json",
            success:function(data){
                if(data.code == "1"){
                    window.location.href=ctx+"/admin/systemManager/userManager";
                }else {
                    alert("温馨提示：" + data.msg);
                }
            }
        });
	}
}

function changeChongzhiNum(obj){
	obj.value=obj.value.replace(/[^-\d]/g,'')
	var count = obj.value;
	if(count == "" || count == "0"){
		parent.window.$("#promptTxt").html("请输入正确的金币数量");
	}else if(count > 0){
		parent.window.$("#promptTxt").html("你好，您将给"+parent.window.$("#chongzhiDialog_userId").html()+"运营号上"+count+"分");
	}else if(count< 0){
		parent.window.$("#promptTxt").html("你好，您将给"+parent.window.$("#chongzhiDialog_userId").html()+"运营号下"+-count+"分");
	}
}
//上下分
function bjs(userId,goldCoinCount){
	$("#chongzhiDialog_userId").html(userId);
	$("#chongzhiDialog_goldCoinCount").html(goldCoinCount);
    var count = $("#chongzhi_num").val();
    if(count!=null){
        $("#promptTxt").html("你好，您将给"+userId+"运营号充值1分");
        $("#chongzhi_num").attr("onkeyup",window.frameElement.id+".contentWindow.changeChongzhiNum(this)");
    }
	parent.window.Index.dialog({
		resizable: false,
		dialogClass: "no-close",
		width: '620',
		context:$("#chongzhiDialog").html(),
		modal: true,
		title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-rmb yellow'></i> 玩家充值</h4></div>",
		title_html: true,
		buttons: [
			{
				html: "<i class='ace-icon glyphicon glyphicon-ok bigger-110'></i>&nbsp; 保存",
				"class" : "btn btn-primary btn-minier",
				click: function() {
                    count = parent.window.$("#chongzhi_num").val();;
                    if(count == undefined){
                        count = '';
                    }
                    var goldLv = parent.window.$("#goldLv").val();
                    if(goldLv == undefined){
                        goldLv = '';
                    }
                    if((count == '') && (goldLv == '')){
                        return;
                    }
					$.ajax({
						type:"POST",
						url:ctx+"/admin/usermanager/chargeYYHJBS",
						data:"userId="+userId+"&count="+count+"&goldLv="+goldLv,
						cache:false,
						success:function(data){
                            if(data.code == 0){
                                alert(data.msg);
                            }else {
                                refreshPage();
                				alert("成功!");
                            }
						}
					});
					parent.window.$( this ).dialog( "close" );
				}
			}
			,
			{
				html: "<i class='ace-icon glyphicon glyphicon-remove bigger-110'></i>&nbsp; 取消",
				"class" : "btn btn-minier",
				click: function() {
					parent.window.$( this ).dialog( "close" );
				}
			}
		]
	});
}